unit uCadastroCliente;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, uCadastroGenerico, dxSkinsCore, dxSkinsdxBarPainter, dxSkinBlack,
  dxSkinBlue, dxSkinOffice2007Black, dxSkinOffice2007Blue,
  dxSkinOffice2007Green, dxSkinOffice2007Pink, dxSkinOffice2007Silver, StdCtrls,
  Buttons, DBCtrls, Mask, ZSequence, DB, ZAbstractRODataset, ZAbstractDataset,
  ZAbstractTable, ZDataset, dxBar, cxClasses, ActnList, ImgList, ExtCtrls,
  uCadastroDependente, cxGraphics, cxControls, cxLookAndFeels,
  cxLookAndFeelPainters, cxContainer, cxEdit, cxTextEdit, cxMaskEdit,
  cxDropDownEdit, cxCalendar, cxDBEdit,
  uCadastroContrato, dxSkinOffice2010Black, dxSkinOffice2010Blue,
  dxSkinOffice2010Silver;

type
  TfCadastroClientes = class(TfCadastroGenerico)
    gb1: TGroupBox;
    lbl1: TLabel;
    lbl10: TLabel;
    lbl11: TLabel;
    lbl12: TLabel;
    lbl2: TLabel;
    lbl3: TLabel;
    lbl4: TLabel;
    lbl5: TLabel;
    lbl6: TLabel;
    lbl7: TLabel;
    lbl8: TLabel;
    lbl9: TLabel;
    dbcbbSexo: TDBComboBox;
    dbedtCidade: TDBEdit;
    dbedtCodigo: TDBEdit;
    dbedtCPF: TDBEdit;
    dbedtEndereco: TDBEdit;
    dbedtFone: TDBEdit;
    dbedtFonecel: TDBEdit;
    dbedtNome: TDBEdit;
    dbedtRG: TDBEdit;
    dbedtStatus: TDBEdit;
    dbmmo1: TDBMemo;
    gbAssociar: TGroupBox;
    btnDependente: TBitBtn;
    btnContrato: TBitBtn;
    btnDespesaExtra: TBitBtn;
    dbcalEditDataEmissao: TcxDBDateEdit;
    procedure actAdicionarExecute(Sender: TObject);
    procedure actGravarExecute(Sender: TObject);
    procedure actDesfazerExecute(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure btnDependenteClick(Sender: TObject);
    procedure btnContratoClick(Sender: TObject);
  private
    { Private declarations }
    procedure HabilitaBotoesExtras(aBool: Boolean);
  public
    { Public declarations }
  end;

var
  fCadastroClientes: TfCadastroClientes;

implementation

uses uDataModule;

{$R *.dfm}

procedure TfCadastroClientes.actAdicionarExecute(Sender: TObject);
begin
  inherited;
  dbedtCodigo.Text := IntToStr(seqCadastro.GetNextValue);
  dbedtStatus.Text := 'ATIVO';
  HabilitaBotoesExtras(false);
end;

procedure TfCadastroClientes.actDesfazerExecute(Sender: TObject);
begin
  inherited;
  HabilitaBotoesExtras(true);
end;

procedure TfCadastroClientes.actGravarExecute(Sender: TObject);
begin
  inherited;
  HabilitaBotoesExtras(true);
  DataModule1.tblClientes.Refresh;
  DataModule1.tblContratos.Refresh;
  DataModule1.tblDependentes.Refresh;
  DataModule1.tblParcelasRecebimentos.Refresh;
  DataModule1.qryClienteContrato.Refresh;
  DataModule1.qryClienteDespesas.Refresh;
  DataModule1.tblclientes2.Refresh;


end;

procedure TfCadastroClientes.btnContratoClick(Sender: TObject);
var
  aFCadastro: TfCadastroContrato;
begin
  try
    aFCadastro:= TfCadastroContrato.Criar('contratos','seqcontratos');
    aFCadastro.Modo := MCInsereVARIOS;
    aFCadastro.NomeResponsavel:= tblCadastro.FieldByName('nome').AsString;
    aFCadastro.CPFContratante:= tblCadastro.FieldByName('cpf').AsString;
    aFCadastro.CodCliente := tblCadastro.FieldByName('cod_cliente').AsInteger;
    aFCadastro.ShowModal;
  finally
    aFCadastro.Free;
  end;
end;

procedure TfCadastroClientes.btnDependenteClick(Sender: TObject);
var
  aFCadastro: TfCadastroDependente;
begin
  try
    aFCadastro:= TfCadastroDependente.Criar('dependentes','seqdependentes');
    aFCadastro.dsTitular.DataSet := self.tblCadastro;
    aFCadastro.Modo := MCInsereVARIOS;
    aFCadastro.ShowModal;
  finally
    aFCadastro.Free;
  end;
end;


procedure TfCadastroClientes.FormShow(Sender: TObject);
begin
  inherited;
  HabilitaBotoesExtras(Modo = MCEdita);
  if Modo <> MCEdita then
  begin
    dbedtCodigo.Text := IntToStr(seqCadastro.GetNextValue);
    dbedtStatus.Text := 'ATIVO';
  end;
end;

procedure TfCadastroClientes.HabilitaBotoesExtras(aBool: Boolean);
begin
  btnDependente.Enabled := aBool;
  btnDespesaExtra.Enabled := aBool;
  btnContrato.Enabled := aBool;
end;

end.
